package com.cy.pj.common.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

//工具类一般都使用static修饰
//存储对外提供请求的方法
//静态方法可以重写但不可以多态

/**
 * 通过spring提供RequestContextHolder对象获取请求属性对象
 */
public class ServletUtil {
    public static HttpServletRequest getRequest(){
        return getRequestAttributes().getRequest();
    }
    public static ServletRequestAttributes getRequestAttributes(){
        return (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    }
}
